package org.jeecg.modules.simulator.line;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.jeecg.modules.simulator.model.line.Line;
import org.jeecg.modules.simulator.model.person.Person;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @program: 加载线的基础数据
 * @description:
 * @author: renzhg
 * @create: 2024-08-30 11:13
 **/
public class LineFactory implements  LineLoader{



Map<String,Line> lineMap=new HashMap<>();




public Map<String,Line> getLineMap(){
    return lineMap;
}

   public List<Line> readLine(String linepath){
       List<Line> lineList=new ArrayList<>();
       try {
           String jsonString = new String(Files.readAllBytes(Paths.get(linepath)));
           JSONArray jsonArray = JSON.parseArray(jsonString);
           for (int i = 0; i < jsonArray.size(); i++) {
               Line line = JSON.parseObject(jsonArray.getJSONObject(i).toString(), Line.class);
               lineList.add(line);
           }

       } catch (IOException e) {
           e.printStackTrace();
       }

       return lineList;
   }


   @Override
    public void loadData(){
      List<Line>  lines= readLine("D:/aaaa/linedata.json");
        lines.stream().forEach(line -> lineMap.put(line.getLineId(),line));


    }
}
